from rest_framework.filters import BaseFilterBackend


class MinFilterBackend(BaseFilterBackend):
    """
    前端传:min_id/max_id
    """

    def filter_queryset(self, request, queryset, view):
        # 给视图类的queryset，添加新的条件
        # 就是我们在类里面配置的
        # queryset=models.Release.objects.filter(is_show=True, is_delete=False).order_by('-id')
        min_id = request.query_params.get('min_id')
        # print(min_id, 'min_id')
        if min_id:
            return queryset.filter(id__lt=min_id).order_by('-id')
        return queryset


class MaxFilterBackend(BaseFilterBackend):
    def filter_queryset(self, request, queryset, view):
        max_id = request.query_params.get('max_id')
        # print(max_id, 'max_id')

        if max_id:
            # print(queryset, '>>>>>>>>>>>>>')
            return queryset.filter(id__gt=max_id).order_by('id')

        return queryset
